package com.elong.qadev.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.elong.qadev.dao.WebuiCaseDaoI;
import com.elong.qadev.entity.WebuiCase;

@Repository("webuiCaseDao")
public class WebuiCaseDaoImpl implements WebuiCaseDaoI {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public WebuiCase getWebuiCase(int parseInt) {
		Criteria c = sessionFactory.getCurrentSession().createCriteria(
				WebuiCase.class);
		c.add(Restrictions.eq("caseId", parseInt));
		if(c.list().isEmpty()){
			return null;
		}
		WebuiCase e = (WebuiCase) c.list().get(0);
		return e;
	}

	@Override
	public boolean saveOrUpdateWebuiCase(WebuiCase wc) {
		sessionFactory.getCurrentSession().saveOrUpdate(wc);
		return true;
	}

	@Override
	public boolean deleteWebuiCase(int parseInt) {
		WebuiCase e = getWebuiCase(parseInt);
		sessionFactory.getCurrentSession().delete(e);
		return true;
	}
}
